package com.example.firstjavamqtt.factory;

import com.example.firstjavamqtt.Constants.DeviceTypeConstants;
import com.example.firstjavamqtt.factory.strategy.DeviceLogMessage.DeviceLogMessageStrategy;

import com.example.firstjavamqtt.factory.strategy.DeviceLogMessage.InfraredMonitorMessageLogStrategy;
import com.example.firstjavamqtt.factory.strategy.DeviceLogMessage.LedLogMessageStrategy;
import com.example.firstjavamqtt.factory.strategy.DeviceLogMessage.TemperatureHumidityMessageStrategy;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

//转化操作消息策略工厂模式
@Component
public class OperationFactory{


    private static final Map<String, DeviceLogMessageStrategy> strategies = new HashMap<>();

    static {
        strategies.put(DeviceTypeConstants.SIMPLE_LED,new LedLogMessageStrategy());
        strategies.put(DeviceTypeConstants.TEMP_HUMIDITY,new TemperatureHumidityMessageStrategy());
        strategies.put(DeviceTypeConstants.INFRARED,new InfraredMonitorMessageLogStrategy());
    }

    public static String getOperation(String string,String deviceType) {
        return strategies.get(deviceType).getOperation(string);
    }
}
